
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>找回密码</title>
  <link rel="stylesheet" href="../../css/aui.css" />
	<link rel="stylesheet" href="../../css/my/forget_password.css">
</head>
<body id="body" style="cursor: pointer;">
<!-- TODO: 忘记密码 -->
<ul class="aui-list aui-form-list from_padded aui-padded-t-15" style="border:none;">
	<form id="myform" role="form" action="#" method="POST">
    <li class="aui-list-item">
      <label style="width:6rem;line-height:2.8rem;">公司名:</label>
			<input type="text" name="company_name" placeholder="请输入公司名">
		</li>
		<li class="aui-list-item">
      <label style="width:6rem;line-height:2.8rem;">手机号:</label>
			<input type="text" name="mobile" placeholder="请输入手机号码">
		</li>
		<li class="aui-list-item col_center">
      <label style="width:9.5rem;line-height:2.8rem;">验证码:</label>
			<input type="text" name="code" placeholder="验证码">
			<div class="aui-btn aui-btn-info aui-btn-outlined aui-btn-sm" onclick="get_verification(this)">获取验证码</div>
		</li>
		<div class="aui-btn aui-btn-block btn_padded reset" onclick="submit_reset()">重置</div>
	</form>
</ul>

</body>
</html>
<script type="text/javascript" src="../../script/aui/api.js"></script>
<script type="text/javascript" src="../../script/extend/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../../script/aui/aui-toast.js" ></script>
<script type="text/javascript" src="../../script/config.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>

<script type="text/javascript">
    apiready = function() {
        api.parseTapmode();
    }

  var company_id;
  //获取验证码
  function get_verification(obj){
      var company_name =  $('input[name=company_name]').val();
      var mobile  = $('input[name=mobile]').val();

      if (!isDefine(company_name)) {
					$toast('公司名不能为空');
          return false;
      }

			if (!isDefine(mobile)) {
				  $toast('手机号不能为空');
          return false;
			} else {
				if (!checkMobile(mobile)) {
					return false;
				}
			}
      ajax({
          url: Config.user.getCode,
          data: {mobile:mobile,companyName:company_name}
      },function(data){
          if (data.code == 1) {
            company_id = data.data.company_id;
              startCountdown(obj);
          } else {
						$toast(data.msg);
          }
      });
  }
    // TODO: 忘记密码
    function submit_reset(){
			  var company_name =  $('input[name=company_name]').val();
        var code   = $('input[name=code]').val();
        var mobile = $('input[name=mobile]').val();

				if (!isDefine(company_name)) {
						$toast('公司名不能为空');
	          return false;
	      }

				if (!isDefine(mobile)) {
					  $toast('手机号不能为空');
	          return false;
				} else {
					if (!checkMobile(mobile)) {
						return false;
					}
				}

				if (!isDefine(code)) {
						$toast('验证码不能为空');
	          return false;
	      } else {
						var reg = /^\d{6}$/;
						if (!reg.test(code)) {
							$toast('验证码格式错误');
							return false;
						}
				}
        ajax({
            url: Config.user.checkCode,
            data: {mobile:mobile,code:code}
        },function(data){
              if (data.code == 1) {
                  //将手机号码存在本地
                  api.openWin({
                      name: 'reset_password_win',
                      url: './reset_password_win.html',
                      pageParam: {
                          mobile : mobile,
                          company_id : company_id
                      }
                  });

              } else {
									$toast(data.msg);
              }
        });
    }



    function startCountdown(obj){
        var s = 60;
        $(obj).text(s+'s');
        $(obj).attr("onclick","");
        smstime = setInterval(function(){
            s--;
            $(obj).text(s+'s');
            if(s == 0){
                clearInterval(smstime);
                $(obj).text("获取验证码");
                $(obj).attr("onclick","get_verification(this)");
            }
        },2000);
    }

</script>
